package com.ruoyi.service.impl;

import com.github.houbb.sensitive.word.api.IWordDeny;
import com.ruoyi.domain.T18;
import com.ruoyi.domain.T22;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.service.IT18Service;
import com.ruoyi.service.IT22Service;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Service
@AllArgsConstructor
public class MyWordDenyImpl implements IWordDeny {
    @Autowired
    private IT18Service t18Service;
    @Autowired
    private TokenService tokenService;
    @Autowired
    private IT22Service t22Service;

    private HttpServletRequest request;

    @Autowired
    public MyWordDenyImpl( HttpServletRequest request) {
        this.request = request;
    }

    public List<String> getStrings(){
        Long userId=tokenService.getLoginUser(request).getUserId();
        T18 t18 = t18Service.selectT18ByF1801(userId);
        Long ComId = t18.getF0301();
        List<T22> sensitiveWordLibs = t22Service.findAllByF0301((ComId));
        List<String> list = sensitiveWordLibs.stream().map(s -> s.getWord()).collect(Collectors.toList());
        return list;
    }

    @Override
    public List<String> deny() {
        return getStrings();
    }
}
